/**
 * Created by zyd on 16/6/23.
 */
var fs = require('fs');
var path = require('path');
var toMarkdown = require('to-markdown');
var Promise = require('bluebird');

var inputPath = path.resolve(__dirname, 'articles');
var outputPath = path.resolve(__dirname, 'mds');


fs.readdir(inputPath, function (err, files) {
    files.forEach(function (filename) {
        fs.readFile(inputPath + '/' + filename, function (err, data) {
            var md;
            if (err) {
                return console.error(err)
            } else {
                md = toMarkdown(data.toString());
                var outname = outputPath + '/' + filename.slice(0, -4) + 'md';
                
                fs.writeFile(outname, md, function (err) {
                    if (err) {
                        return console.error(err);
                    }
                    console.log("数据写入成功！")
                });
            }

        });
    })
});

